package com.ruoyi.web.controller.mall.goodsTagLink.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.goodsTagLink.domain.GoodsTagLink;
import com.ruoyi.web.controller.mall.goodsTagLink.service.IGoodsTagLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品标签关联Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/goodsTagLink")
public class GoodsTagLinkController extends BaseController
{
    private String prefix = "mall/goodsTagLink";

    @Autowired
    private IGoodsTagLinkService goodsTagLinkService;

//    @RequiresPermissions("mall:goodsTagLink:view")
    @GetMapping()
    public String goodsTagLink()
    {
        return prefix + "/goodsTagLink";
    }

    /**
     * 查询商品标签关联列表
     */
//    @RequiresPermissions("mall:goodsTagLink:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsTagLink goodsTagLink)
    {
        startPage();
        List<GoodsTagLink> list = goodsTagLinkService.selectGoodsTagLinkList(goodsTagLink);
        return getDataTable(list);
    }

    /**
     * 导出商品标签关联列表
     */
//    @RequiresPermissions("mall:goodsTagLink:export")
    @Log(title = "商品标签关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsTagLink goodsTagLink)
    {
        List<GoodsTagLink> list = goodsTagLinkService.selectGoodsTagLinkList(goodsTagLink);
        ExcelUtil<GoodsTagLink> util = new ExcelUtil<GoodsTagLink>(GoodsTagLink.class);
        return util.exportExcel(list, "goodsTagLink");
    }

    /**
     * 新增商品标签关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品标签关联
     */
//    @RequiresPermissions("mall:goodsTagLink:add")
    @Log(title = "商品标签关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsTagLink goodsTagLink)
    {
        return toAjax(goodsTagLinkService.insertGoodsTagLink(goodsTagLink));
    }

    /**
     * 修改商品标签关联
     */
    @GetMapping("/edit/{goodsId}")
    public String edit(@PathVariable("goodsId") String goodsId, ModelMap mmap)
    {
        GoodsTagLink goodsTagLink = goodsTagLinkService.selectGoodsTagLinkById(goodsId);
        mmap.put("goodsTagLink", goodsTagLink);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品标签关联
     */
//    @RequiresPermissions("mall:goodsTagLink:edit")
    @Log(title = "商品标签关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsTagLink goodsTagLink)
    {
        return toAjax(goodsTagLinkService.updateGoodsTagLink(goodsTagLink));
    }

    /**
     * 删除商品标签关联
     */
//    @RequiresPermissions("mall:goodsTagLink:remove")
    @Log(title = "商品标签关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(goodsTagLinkService.deleteGoodsTagLinkByIds(ids));
    }
}
